//
// Created by gogoqiu on 2021/12/13.
//

#ifndef WXSIMPLE_CHATWND_H
#define WXSIMPLE_CHATWND_H

#include "wx/wx.h"
#include <wx/panel.h>		// Needed for wxPanel
#include <wx/notebook.h>		// Needed for wxNotebookEvent
#include "wx/menu.h"

//#include "Types.h"
typedef uint64_t	int64;
typedef uint64_t	uint64;

class CFriend;
class CChatSelector;
class CFriendListCtrl;
class CMD4Hash;

/*
 * view
 * regular message bind callback
 *
 */
class CChatWnd : public wxPanel
{
public:
    explicit CChatWnd(wxWindow* pParent = nullptr);
    ~CChatWnd()  = default;;

    void StartSession(CFriend* friend_client, bool setFocus = true);

    void	UpdateFriend(CFriend* toUpdate);
    void	RemoveFriend(CFriend* toDel);

    void	ProcessMessage(uint64 sender, const wxString& message);
    void	ConnectionResult(bool success, const wxString& message, uint64 id);

    void	SendMessage(const wxString& message,
                        const wxString& client_name = wxEmptyString, uint64 to_id = 0);

    bool	IsIdValid(uint64 id);
    void	ShowCaptchaResult(uint64 id, bool ok);
    void	EndSession(uint64 id);

protected:
    /**
     * Event-handler for displaying the chat-popup menu.
     */
    void	OnNMR_clickChatTab(wxMouseEvent& evt);
    /**
     * Event-handler fo the Close item on the popup-menu.
     */
    void	OnPopupClose(wxCommandEvent& evt);

    /**
     * Event-handler fo the CloseAll item on the popup-menu.
     */
    void	OnPopupCloseAll(wxCommandEvent& evt);

    /**
     * Event-handler fo the CloseOthers item on the popup-menu.
     */
    void	OnPopupCloseOthers(wxCommandEvent& evt);

    /**
     * Event-handler fo the AddFriend item on the popup-menu.
     */
    void	OnAddFriend(wxCommandEvent& evt);

    void	OnBnClickedCsend(wxCommandEvent& evt);
    void	OnBnClickedCclose(wxCommandEvent& evt);
    void	OnAllPagesClosed(wxNotebookEvent& evt);
    void	CheckNewButtonsState();

    //! Variable used to ensure that the popup menu doesn't get displayed twice.
    wxMenu* m_menu;
    //! Pointer to the control serving as the friend list
    CFriendListCtrl* friendListCtrl;
    //! Pointer to the chat tabs.
    CChatSelector*	chatSelector;
DECLARE_EVENT_TABLE()
};



#endif //WXSIMPLE_CHATWND_H
